<?php

namespace frontend\modules\dynamic\models;

use Yii;
use yii\data\ActiveDataProvider;
use yii\web\Link;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "{{%dynamic}}".
 *
 * @property int $id
 * @property string $user_id 用户ID
 * @property string $content
 * @property int $direction 动态类型：0主动动态，1被动动态
 * @property int $retweet_id 转发动态原始ID
 * @property int $status
 * @property string $created_at
 * @property string $updated_at
 * @property string $deleted_at
 */
class DynamicCommentSearch extends \common\models\dynamic\DynamicComment {

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $id
     *
     * @return ActiveDataProvider
     */
    public function search($id) {
        $query = static::findx($id)->andWhere([
            'status' => static::STATUS_ACTIVE,
            'deleted_at' => 0,
        ])->with('user');

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        Yii::$app->db->cache(function($db) use($dataProvider) {
            $dataProvider->prepare();
        }, 60);

        return $dataProvider;
    }

    public function fields() {
        return [
            "id",
            "user_id",
            "dynamic_id",
            "comment_id",
            "post",
            "device_id",
            "status",
            "created_at",
            "updated_at",
            "deleted_at",
            'is_like'=>'isLike',
            'user'
        ];
    }

}
